; (function () {
	window.fcUtil = window.u = {
		I64BIT_TABLE: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-'.split(''),
		updataHistory: function () {
			let state = true;
			let url = location.href.match(/\/workshop.*/)[0];
			let historyArr = store.get('historyArr') || [];
			if (historyArr.length) {
				if (historyArr[historyArr.length - 1] != url) {
					historyArr.push(url);
					state = true;
				} else {
					state = false;
				}
			} else {
				historyArr.push(url);
				state = true;
			}
			this.historyArr = historyArr;
			store.set('historyArr', historyArr);
			return state;
		},
		sHeight: function (obj) {
			let selectedObj;
			if (obj) {
				selectedObj = obj.find('.s-height:visible');
			} else {
				selectedObj = $('.s-height:visible');
			}
			selectedObj.each(function () {
				if ($(this).parents('.wd-s-height').length) {
					return true;
				}
				if ($(this).hasClass('side-page-content').length == 0 && $(this).data('s-height') && $(this).find('.edui-editor').length) {
					return true;
				}
				let tempDestroyScroll;
				let totalHeight = 0;
				let $this = $(this);
				$this.siblings(':visible:not([id^=ascrail])').each(function () {
					if ($(this).css('position') != 'absolute' && !$(this).hasClass('s-height-ignore')) {
						totalHeight += $(this).outerHeight(true)
					}
				});
				let $parent = $this.parent();
				if ($parent.hasClass('mCSB_container')) {
					$parent = $parent.parent();
				}
				let h = $parent.height() - totalHeight - $(this).outerHeight(true) + $(this).height();
				if ($(document).width() > 767) {
					if (h > 0) {
						$this.height(h);
						$this.attr('data-s-height', 'true')
					}
				} else {
					// $this.attr('data-s-height', 'false')
					// $this.height('auto');
				}
			});
			$('[data-p-height]:visible').each(function () {
				$(this).height($($(this).data('p-height')).height());
			});
		},
		formToJson: function (elemtnt) {
			return $(elemtnt).serializeJSON();
		},
		isPc: function () {
			if ($('body').width() <= 767) {
				$('html').attr('data-type', 'mobile');
				return false;
			} else {
				$('html').attr('data-type', 'pc');
				return true;
			}
		},
		loading: function (element) {
			return false;
			let html = '<div class="loading-container">' +
				'<div class="spinner">' +
				'<div class="rect1"></div>' +
				'<div class="rect2"></div>' +
				'<div class="rect3"></div>' +
				'<div class="rect4"></div>' +
				'<div class="rect5"></div>' +
				'</div>' +
				'<p>加载中</p>' +
				'</div>'
			if (element) {
				$(element).html(html);
			} else {
				$('#wd-pageContent').html(html)
			}
		},
		getParam: function (key) {
			let reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)");
			let r = window.location.search.substr(1).match(reg);
			if (r != null) return unescape(r[2]);
			return null;
		},
		getMapLength: function (obj) {
			let count = 0;
			for (let i in obj) {
				count++;
			}
			return count;
		},
		setMenuSelect: function () {
			let key = location.href.replace(location.origin, '');
			let li = $('a[data-href="' + key + '"]').parent('li').addClass("active");
			if (!li.length) {
				key = location.href.match(/key=(\w+)/)[1];
				li = $('.site-menu-item a[data-key*="' + key + '"]').parent().addClass("active");
			}
			//如果是三级菜单 展开二级菜单
			if (li.parent().hasClass('site-menu-sub')) {
				li.parent().parent().addClass('has-sub open')
			}
			let tabPane = li.parents('.tab-pane');
			tabPane.addClass('active').siblings('.active').removeClass('active');
			let id = tabPane.attr('id');
			$('a[aria-controls="' + id + '"]').parent('li').addClass('active').siblings('.active').removeClass('active');

			//修正二级菜单 .open
			$('.site-menu-item.has-sub.open').each(function (i, li) {
				if ($(li).find('.active').length == 0) {
					$('.site-menu-item.has-sub.open').removeClass('open');
				}
			})
		},
		setIcon: function () {
			$('i[data-icon]:not(.i-icon)').each(function (index, i) {
				$(i).html('<svg class="icon" aria-hidden="true"><use xlink:href="#' + $(i).data('icon') + '"></use></svg>').addClass('i-icon');
			})
		},
		/**
		 * 更新权限
		 */
		updataAuthority: function () {
			return false;
			$('[data-authority]').each(function (i, e) {
				if (authority[$(e).data('authority')] !== true) {
					$(e).remove();
				}
			})
		},
		/**
		 * 异步加载javascript
		 */
		loadScript: function (url, callback) {
			let script = document.createElement("script")
			script.type = "text/javascript";
			if (script.readyState) { //IE 
				script.onreadystatechange = function () {
					if (script.readyState == "loaded" ||
						script.readyState == "complete") {
						script.onreadystatechange = null;
						if (callback)
							callback();
					}
				};
			} else { //Others: Firefox, Safari, Chrome, and Opera 
				script.onload = function () {
					if (callback)
						callback();
				};
			}
			script.src = url;
			document.body.appendChild(script);
		},
		math: {
			/**
			 * 实现对数字保留两位小数一位自动补零
			 * @param  {[type]} number [description]
			 * @return {[type]}        [description]
			 */
			decimal: function (number) {
				if (number == 0) {
					return '0.00';
				}
				let value;
				if (number == '' || number == null || number == undefined) {
					return '';
				}
				if (fcUtil.math.isNumber(number)) {
					value = Math.round(parseFloat(number) * 100) / 100;
				} else {
					return '0.00';
				}
				let xsd = value.toString().split(".");
				if (xsd.length == 1) {
					value = value.toString() + ".00";
					return value;
				}
				if (xsd.length > 1) {
					if (xsd[1].length < 2) {
						value = value.toString() + "0";
					}
					return value;
				}
			},
			isNumber: function (n) {
				return !isNaN(parseFloat(n)) && isFinite(n);
			}
		},
		clone: function (obj) {
			let newobj = {};
			for (let attr in obj) {
				newobj[attr] = obj[attr];
			}
			return newobj;
		},
		hash: function (input) {
			let hash = 5381;
			let i = input.length - 1;

			if (typeof input == 'string') {
				for (; i > -1; i--)
					hash += (hash << 5) + input.charCodeAt(i);
			}
			else {
				for (; i > -1; i--)
					hash += (hash << 5) + input[i];
			}
			let value = hash & 0x7FFFFFFF;

			let retValue = '';
			do {
				retValue += this.I64BIT_TABLE[value & 0x3F];
			}
			while (value >>= 6);

			return retValue;
		},
		isVisible: function ($node, height, scrollTop) {
			let offSetTop = $node.offset().top;
			if (offSetTop < (scrollTop + 61 + 60)) {
				return true;
			} else {
				return false;
			}
		},
		rotateLoading(arg1, arg2) {
			if (arg1) {
				$('#rotateCircle').find('.retateCircleContent').html(arg2 || '正在执行,请稍等...');
				$('#rotateCircle').css('display', 'block');
			} else {
				$('#rotateCircle').css('display', 'none');
				$('#rotateCircle').find('.retateCircleContent').html('正在执行,请稍等...');
			}
		},
		log(str) {
			if (isDebug) {
				console.log(str);
			}
		},
		echartsSetOption(ec) {
			let myChart = echarts.init(document.getElementById(ec.id));
			if (ec.Merge) {
				myChart.setOption(ec.option, ec.Merge);
			} else {
				myChart.setOption(ec.option);
			}
			$('#' + ec.id).data('echart', myChart);
			windowSesizeArr.push(myChart.resize);
		},
		loadJS(srcArr) {
			let promiseArr = [];
			for (let i = 0; i < srcArr.length; i++) {
				promiseArr.push(new Promise((resolve, reject) => {
					let script = document.createElement('script');
					let head = document.getElementsByTagName('head')[0];
					script.src = srcArr[i];
					head.appendChild(script);
					script.onload = script.onreadystatechange = function () {
						resolve()
					}
				}))
			};

			return new Promise((resolve, reject) => {
				Promise.all(promiseArr).then(() => {
					resolve(666);
				})
			})
		},
		asyncRequire(srcArr) {
			return new Promise((resolve, reject) => {
				requirejs(srcArr, function (result) {
					resolve(result)
				});
			})
		}
	};
	window.log = fcUtil.log;
	//---------------------------
	Date.prototype.Format = function (fmt) {          //author: Shf
		let o = {
			"M+" : this.getMonth() + 1,
			//月份
			"d+" : this.getDate(),
			//日
			"h+" : this.getHours(),
			//小时
			"m+" : this.getMinutes(),
			//分
			"s+" : this.getSeconds(),
			//秒
			"q+" : Math.floor((this.getMonth() + 3) / 3),
			//季度
			"S"  : this.getMilliseconds()              //毫秒

		};
		if (/(y+)/.test(fmt)) {
			fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
		}
		for (let k in o) {
			if (new RegExp("(" + k + ")").test(fmt)) {
				fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
			}
		}
		return fmt;
	};
})();

